package com.gcl.rabbitmq;

import com.gcl.rabbitmq.utils.RabbitMQUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consumer01 {

    public static final String EXCHANGE_NAME = "logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMQUtils.getChannel();
        // 声明交换器
        channel.exchangeDeclare(EXCHANGE_NAME,"fanout");
        // 声明临时的队列
        String QUEUE_NAME = channel.queueDeclare().getQueue();
        // 将临时的队列绑定到交换机上
        channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "");
        // 进行消费消息
        DeliverCallback deliverCallback = (consumeTag,Delivery) -> {
            String msg = new String(Delivery.getBody());
            System.out.println("打印消息为 "+ msg);
        };
        CancelCallback cancelCallback = (consumeTag) -> {

        };
        channel.basicConsume(QUEUE_NAME, true, deliverCallback , cancelCallback);

    }
}
